package com.xique.sys.api.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.xique.common.core.domain.R;
import com.xique.sys.api.RemoteSysUserService;
import com.xique.sys.api.model.LoginUser;

/**
 * 用户服务降级处理
 *
 * @author xique
 */
@Component
public class RemoteSysUserFallbackFactory implements FallbackFactory<RemoteSysUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteSysUserFallbackFactory.class);

    @Override
    public RemoteSysUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteSysUserService()
        {
            @Override
            public R<LoginUser> getUserInfo(String username)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }
        };
    }
}
